<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@page import="java.util.*"%>
<%@page import="weaver.file.FileUpload"%>
<%@page import="weaver.general.Util"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="weaver.hrm.*" %>
<%@ page import="weaver.systeminfo.*" %>
<%@page import="weaver.general.Util" %>
<%@page import="java.sql.Timestamp" %>
<%@page import="weaver.conn.ConnStatement" %>
<%@page import="weaver.conn.RecordSet" %>
<%@page import="weaver.cowork.*" %>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="weaver.hrm.resource.ResourceComInfo" %>
<%@page import="weaver.hrm.job.JobTitlesComInfo" %>
<%@page import="weaver.hrm.company.DepartmentComInfo" %>
<%@page import="weaver.mobile.plugin.ecology.service.HrmResourceService" %>

<%@page import="oracle.sql.CLOB"%>
<%@page import="java.io.Writer"%>
<%@page import="weaver.blog.WorkDayDao"%>
<%@page import="weaver.blog.BlogShareManager"%>
<%@page import="weaver.blog.AppItemVo"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="weaver.blog.BlogManager"%>
<%@page import="weaver.blog.BlogDiscessVo"%>
<%@page import="weaver.blog.BlogReplyVo"%>
<%@page import="weaver.blog.BlogDao"%>
<%@page import="weaver.blog.AppDao"%>
<%@page import="weaver.blog.webservices.BlogServiceImpl"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="weaver.blog.BlogReportManager"%>

<jsp:useBean id="blogDao" class="weaver.blog.BlogDao"></jsp:useBean> 
<jsp:useBean id="CoworkTransMethod" class="weaver.general.CoworkTransMethod" scope="page" />
<jsp:useBean id="ResourceComInfo" class="weaver.hrm.resource.ResourceComInfo"></jsp:useBean>
<jsp:useBean id="SubCompanyComInfo" class="weaver.hrm.company.SubCompanyComInfo"></jsp:useBean>
<jsp:useBean id="DepartmentComInfo" class="weaver.hrm.company.DepartmentComInfo"></jsp:useBean>
<jsp:useBean id="JobTitlesComInfo" class="weaver.hrm.job.JobTitlesComInfo"></jsp:useBean>


<%
out.clearBuffer();
request.setCharacterEncoding("UTF-8");
FileUpload fu=new FileUpload(request);
HrmResourceService hrs = new HrmResourceService();
String userid = Util.null2String(fu.getParameter("userid"));
User user = hrs.getUserById(Util.getIntValue(userid));
if(user==null) {
	Map result = new HashMap();
	//未登录或登录超时
	result.put("error", "200001");
	JSONObject jo = JSONObject.fromObject(result);
	out.println(jo);
	return;
}

String blogid=Util.null2String(fu.getParameter("blogid"));  //微博id
String fromPage=Util.null2String(fu.getParameter("page"));
String startDate=Util.null2String(fu.getParameter("startDate"));
String endDate=Util.null2String(fu.getParameter("endDate"));
String operation=Util.null2String(fu.getParameter("operation")); //请求类型
String ac=Util.null2String(fu.getParameter("ac"));                   //查询来自页面
String content=Util.null2String(fu.getParameter("content")).replace("'","''");         //搜索内容
String submitdate=Util.null2String(fu.getParameter("submitdate"));  //提交时间分割线，最后显示时间
String attentionWorkDate=Util.null2String(fu.getParameter("workDate"));//我的关注，指定工作日

int currentpage=Util.getIntValue(fu.getParameter("pageindex"),1);  //页数
int pagesize=Util.getIntValue(fu.getParameter("pagesize"),20);       //每页显示条数
int total=Util.getIntValue(fu.getParameter("total"),0);              //总数

int minUpdateid=Util.getIntValue(fu.getParameter("minUpdateid"),0);  //存贮已经取出来的更新提醒最小id

String isFirstPage=Util.null2String(fu.getParameter("isFirstPage")); //我的微博页面判断是否为第一页，第一页才返回编辑器

String groupid=Util.null2String(fu.getParameter("groupid"));  //微博分组id
groupid=groupid.equals("")?"all":groupid;

BlogManager blogManager=new BlogManager(user);

if("".equals(blogid)){
	blogid=""+user.getUID();
}else{
	BlogShareManager shareManager=new BlogShareManager();
	int status=shareManager.viewRight(blogid,userid); //微博查看权限
	if(status<=0){
	  return ;	
	}
}

SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat dateFormat1=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dateFormat2=new SimpleDateFormat("M月d日");
SimpleDateFormat dateFormat3=new SimpleDateFormat("yyyy年M月d日 HH:mm");
SimpleDateFormat timeFormat=new SimpleDateFormat("HH:mm");

SimpleDateFormat calFormat=new SimpleDateFormat("M/d");

Date today=new Date();
String todaydate=dateFormat1.format(today);
String curDate=dateFormat1.format(today);
//submitdate=submitdate.equals("")?curDate:submitdate;  //提交日期

int isNeedSubmit=0;
int todayIsReplayed=0; //今天是否被评论过，如果被评论过就显示今天内容

//检查当前用户 当天是否需要提交
if(!isFirstPage.equals("false")&&userid.equals(blogid)&&operation.equals("myblog")){
   isNeedSubmit=blogDao.isNeedSubmit(user,curDate);
   if(blogDao.getReplyList(userid,curDate,userid).size()>0)
		todayIsReplayed=1;
}

String isManagerScore=blogDao.getSysSetting("isManagerScore");  //启用上级评分

Date startdateTemp=new Date();
String yesterday=dateFormat1.format(startdateTemp);      //昨天
Date d = new Date();
d.setDate(startdateTemp.getDate()-1);
String beforeyesterday=dateFormat1.format(d);//前天

String enableDate="";
String startTmep="";
String endTemp="";
Map conditions=new HashMap();
List updateList=new ArrayList();   //获得更新提醒id list
List discussList=new ArrayList();  //微博记录list
Map  discussMap=null;
Map result = new HashMap();
AppDao appDao=new AppDao();
boolean moodIsActive=appDao.getAppVoByType("mood").isActive();
//周日 周一 周二 周三 周四 周五 周六 
String []week={SystemEnv.getHtmlLabelName(16106,user.getLanguage()),SystemEnv.getHtmlLabelName(16100,user.getLanguage()),SystemEnv.getHtmlLabelName(16101,user.getLanguage()),SystemEnv.getHtmlLabelName(16102,user.getLanguage()),SystemEnv.getHtmlLabelName(16103,user.getLanguage()),SystemEnv.getHtmlLabelName(16104,user.getLanguage()),SystemEnv.getHtmlLabelName(16105,user.getLanguage())};
if(operation.equals("homepage")){      //微博主页
	Map<String, Object> detail = new HashMap<String, Object>();
	List datas = new ArrayList();
	try{
		ResourceComInfo resourceComInfo=new ResourceComInfo();
		JobTitlesComInfo jobTitlesComInfo=new JobTitlesComInfo();
			
		List attentionList=blogManager.getMyAttention(userid,groupid);
		String attentionids="";                                 //所有我关注的人集合,包含自身
		for(int i=0;i<attentionList.size();i++){
			attentionids=attentionids+","+attentionList.get(i);
		}
		if(groupid.equals("all"))
			attentionids+=","+userid;
		attentionids=attentionids.length()>0?attentionids.substring(1):attentionids;
		conditions.put("attentionids",attentionids);
		if(total==0){
			total=blogDao.getBlogDiscussCount(conditions);
		}
		updateList=blogDao.getUpdateDiscussidList(userid);
		discussList=blogManager.getBlogDiscussVOList(userid,currentpage, pagesize,total,conditions);
		
		
		if(discussList.size()>0){
			for(int i=0;i<discussList.size();i++){
				Map map = new HashMap();
				BlogDiscessVo discessVo=(BlogDiscessVo)discussList.get(i);
				if(discessVo==null)
					continue;
				String discussid=discessVo.getId();
				map.put("discussid", Util.null2String(discussid));
				String workdate=discessVo.getWorkdate();
				String showdate=workdate;
				long   todaytime=today.getTime(); 
				if("undefined".equals(workdate)){
					continue;
				}
				long   worktime=dateFormat1.parse(workdate).getTime(); 
				//获取某个工作日到今天已经几天了
				long daysFromWorkDate=(todaytime-worktime)/(24*60*60*1000);
				
				String managerstr=resourceComInfo.getManagersIDs(discessVo.getUserid());
				String createdate="";
				if(discussid!=null)
					createdate=discessVo.getCreatedate();
				else
					createdate=attentionWorkDate;
					
				////提交时间分割线
				boolean isShowDate=false;
				String subline = "";
				if(!createdate.equals(submitdate)){
					submitdate=createdate;
					Date dateTemp=new Date();
					dateTemp.setDate(dateTemp.getDate()-1);
					yesterday=dateFormat1.format(dateTemp);      //昨天
					dateTemp.setDate(dateTemp.getDate()-1);
					beforeyesterday=dateFormat1.format(dateTemp);//前天
					String weekday=week[dateFormat1.parse(submitdate).getDay()];
					
					if(submitdate.equals(todaydate)){
						weekday="今天";
					}else if(submitdate.equals(yesterday)){
						weekday="昨天";
					}
					isShowDate=true;
					showdate=submitdate;
					subline = "以下是"+dateFormat2.format(dateFormat1.parse(submitdate))+"/"+weekday+"&nbsp;&nbsp;提交的内容";
				}
				String divsubline = subline;
				map.put("subline", divsubline);
				String comefrom=discessVo.getComefrom();
				String comefromTemp="";
				if(comefrom.equals("1"))  
					comefromTemp="(来自iPhone)";
				else if(comefrom.equals("2"))  
					comefromTemp="(来自iPad)";
				else if(comefrom.equals("3"))  
					comefromTemp="(来自Android)";          
				else if(comefrom.equals("4"))  
					comefromTemp="(来自Web手机版)";
			    else
			    	comefromTemp="";       	
				AppItemVo  appItemVo=null;
				if(moodIsActive)
				  appItemVo=appDao.getappItemByDiscussId(discussid); 
				String faceimg = "";
				if(appItemVo!=null&&appItemVo.getFaceImg()!=null&&!appItemVo.getFaceImg().equals("")){
					faceimg = "<div class=\"rowWrap moodIcon\" ><img  src=\""+appItemVo.getFaceImg()+"\" /></div>" ;
				}
		
				//地理位置
				List locationList=blogDao.getLocationList(discussid);
				if(locationList!=null&&locationList.size()>0){
					map.put("haslocation",1);
					map.put("location",locationList.get(0));
					map.put("locationData",locationList);
				}else{
					map.put("haslocation",0);
				}
				
				String discussuserid=discessVo.getUserid();            //发表人id
				String isnew=updateList.contains(discussid)?"0":"1";  // 0未读  1 已读
				
				StringBuffer commentstrBuffer = new StringBuffer();
				int repnum1 = 0;
				int repnum2 = 0;
				List replyList=blogDao.getReplyList(discussuserid, discessVo.getWorkdate(), userid);
				//BlogReplyVo replyArray[]=new BlogReplyVo[replyList.size()];
				if(replyList.size()>0){
					commentstrBuffer.append("<div class='commentReply'><ul class='reply'>");
					for(int j=0;j<replyList.size();j++){
						BlogReplyVo replyVo=(BlogReplyVo)replyList.get(j);
						String replyid = Util.null2String(replyVo.getId());
						String replyUserid=replyVo.getUserid();
						String replyUsername=resourceComInfo.getLastname(replyUserid);
						String commentType = Util.null2String(replyVo.getCommentType());//私评1
						if("1".equals(commentType)){
							repnum2++;
							commentstrBuffer.append("<li>"+replyUsername+"&nbsp;&nbsp;"+CoworkTransMethod.getFormateDate(replyVo.getCreatedate(),replyVo.getCreatetime())+"(私评)<br>");
						}else{
							repnum1++;
							commentstrBuffer.append("<li>"+replyUsername+"&nbsp;&nbsp;"+CoworkTransMethod.getFormateDate(replyVo.getCreatedate(),replyVo.getCreatetime())+"<br>");
						}
						commentstrBuffer.append("<span class=\"replaycontent\">"+Util.StringReplace(Util.null2String(replyVo.getContent()),"\r\n","")+"</span></li>");
					}
					commentstrBuffer.append("</ul></div>");
				}
				map.put("workdate", workdate);
				map.put("workdateCal", calFormat.format(dateFormat1.parse(workdate)));
				String weekdayCal=week[dateFormat1.parse(workdate).getDay()];
				if(workdate.equals(todaydate)){
					weekdayCal="今天";
				}else if(workdate.equals(yesterday)){
					weekdayCal="昨天";
				}
				map.put("weekdayCal", weekdayCal);
				
				map.put("replycomments", commentstrBuffer.toString());
				map.put("discussuserid", discussuserid);
				map.put("username", resourceComInfo.getLastname(discussuserid));
				map.put("userimg", resourceComInfo.getMessagerUrls(discussuserid));
				map.put("createdate",Util.null2String(discessVo.getCreatedate()));
				map.put("createtime", Util.null2String(discessVo.getCreatetime()));
				map.put("moodIcon",faceimg);
				String  isreplenish = discessVo.getIsReplenish();
				String bjstr = "";//补交说明
				if(!("0").equals(isreplenish)){
					isreplenish = "1";
					String weekday=week[dateFormat1.parse(workdate).getDay()];
					bjstr = "<div class=\"bjdiv\">补交"+dateFormat2.format(dateFormat1.parse(workdate))+"/"+weekday+"工作微博</div>";
				}
				map.put("bjstr",bjstr);
				map.put("isreplenish",discessVo.getIsReplenish());
				map.put("isnew", isnew);
				if("0".equals(isnew)){
					map.put("noreadimg","<img src=\"/mobilemode/apps/e-cology/blog/imgs/noread_wev8.png\" class=\"noreadimg\" userid=\""+userid+"\" discussid=\""+discussid+"\" discussuserid=\""+discussuserid+"\">");
				}else{
					map.put("noreadimg","");
				}
				String deptname=DepartmentComInfo.getDepartmentname(ResourceComInfo.getDepartmentID(discussuserid));
				map.put("deptname", deptname);//部门名称
				map.put("jbotitle", jobTitlesComInfo.getJobTitlesname(resourceComInfo.getJobTitle(discussuserid)));//岗位名称
				map.put("managerid", resourceComInfo.getManagerID(discussuserid));
				String contents = Util.null2String(discessVo.getContent());//微博内容
				map.put("contents",Util.StringReplace(contents.trim(),"\r\n",""));
				if(repnum1!=0){
					map.put("repnum1","("+repnum1+")");
				}else{
					map.put("repnum1","");
				}
				if(repnum2!=0){
					map.put("repnum2","("+repnum2+")");
				}else{
					map.put("repnum2","");
				}
				datas.add(map);
			}
		}
	}catch(Exception e){
		e.printStackTrace();
	}

	detail.put("datas",datas);
	detail.put("totalSize",total+"");
	if(total == 0){
		out.print("{\"totalSize\":0, \"datas\":[]}");
		return;
	}
	JSONObject json = JSONObject.fromObject(detail);
	out.print(json.toString());
}else if(operation.equals("myblog")){//我的微博
	String islog=Util.null2String(fu.getParameter("islog"));
	Date d1 = new Date();
	RecordSet rs = new RecordSet();
	JSONObject logObj = new JSONObject();
	if(islog.equals("1")){
		logObj.put("d1",d1.getTime());
	}
	
	// 更新访问记录时间
	if(!userid.equals(blogid)){
        blogDao.addVisitRecord(userid, blogid);
	}
	
	ResourceComInfo resourceComInfo=new ResourceComInfo();
	JobTitlesComInfo jobTitlesComInfo=new JobTitlesComInfo();
	enableDate=blogDao.getSysSetting("enableDate");//微博启用时间
	
	Date dateTemp=new Date();
	String todaystr = dateFormat1.format(dateTemp);
	dateTemp.setDate(dateTemp.getDate()-1);
	yesterday=dateFormat1.format(dateTemp);      //昨天
	dateTemp.setDate(dateTemp.getDate()-1);
	beforeyesterday=dateFormat1.format(dateTemp);//前天
	String weekday="";
	
	if(islog.equals("1")){
		Date d2 = new Date();
		logObj.put("d2",d2.getTime());
		logObj.put("d12",(d1.getTime()-d2.getTime()));
	}
	String blogCount=""+blogDao.getMyBlogCount(blogid);               //微博总数
	String myAttentionCount=""+blogDao.getMyAttentionCount(blogid,"all");   //我关注的人总数
	String attentionMeCount=""+blogDao.getAttentionMe(blogid).size();        //关注我的人总数
	
	int blog_makeUpTime = 7;
	int blog_canEditTime = 3;
	try{
		blog_makeUpTime = Util.getIntValue(blogDao.getSysSetting("makeUpTime"));   //微博可补交天数
		blog_canEditTime = Util.getIntValue(blogDao.getSysSetting("canEditTime"));  //微博可编辑天数
	} catch (Exception e) {
		blog_makeUpTime = 7;
		blog_canEditTime = 3;
	}
	
	if(islog.equals("1")){
		Date d3 = new Date();
		logObj.put("d3",d3.getTime());
		logObj.put("d13",(d1.getTime()-d3.getTime()));
	}
	Map<String, Object> detail = new HashMap<String, Object>();
	List datas = new ArrayList();
	try{
		if("".equals(endDate)){
			Date endDateTmp=new Date();
			if(isNeedSubmit!=0||!userid.equals(blogid)||todayIsReplayed==1)  //访问其他用户的微博不显示今天
				endDateTmp.setDate(endDateTmp.getDate());
			else
				endDateTmp.setDate(endDateTmp.getDate());
			endDate=dateFormat1.format(endDateTmp);
			
			startdateTemp=endDateTmp;
			startdateTemp.setDate(endDateTmp.getDate()-pagesize);
			startDate=dateFormat1.format(startdateTemp);
		}else{
			startdateTemp=dateFormat1.parse(endDate);
			Calendar cal = Calendar.getInstance();
			cal.setTime(startdateTemp);
			cal.add(Calendar.DAY_OF_YEAR,-pagesize);
			startdateTemp = cal.getTime();
		}
		String haveNextPage = "0";
		Date startDate1 = new Date();
		startDate1.setDate(startdateTemp.getDate()-1);
		if(startDate1.getTime()>=dateFormat1.parse(enableDate).getTime()){
			haveNextPage = "1";
			startDate=dateFormat1.format(startdateTemp);
			total = pagesize*currentpage+1;
		}else{
			haveNextPage = "0";
			startDate=enableDate;
			total = pagesize*currentpage;
		}
		
		if(islog.equals("1")){
			Date d4 = new Date();
			logObj.put("d4",d4.getTime());
			logObj.put("d14",(d1.getTime()-d4.getTime()));
		}
		discussList=blogManager.getDiscussListAll(blogid,startDate,endDate);
		if(islog.equals("1")){
			Date d5 = new Date();
			logObj.put("d5",d5.getTime());
			logObj.put("d15",(d1.getTime()-d5.getTime()));
		}
		if(discussList.size()>0){
			for(int i=0;i<discussList.size();i++){
				Map map = new HashMap();
				BlogDiscessVo discessVo=(BlogDiscessVo)discussList.get(i);
				if(discessVo==null)
					continue;
				String discussid=discessVo.getId();
				map.put("discussid", Util.null2String(discussid));
				String workdate=Util.null2String(discessVo.getWorkdate());
				
				String showdate=workdate;
				long   todaytime=today.getTime(); 
				long   worktime=dateFormat1.parse(workdate).getTime(); 
				//获取某个工作日到今天已经几天了
				long daysFromWorkDate=(todaytime-worktime)/(24*60*60*1000);
				
				String managerstr=resourceComInfo.getManagersIDs(discessVo.getUserid());
				String createdate="";
				if(discussid!=null)
					createdate=discessVo.getCreatedate();
				else
					createdate=attentionWorkDate;
				
				String contents = Util.null2String(discessVo.getContent());//微博内容
					
				String comefrom=Util.null2String(discessVo.getComefrom());
				String comefromTemp="";
				if(comefrom.equals("1"))  
					comefromTemp="(来自iPhone)";
				else if(comefrom.equals("2"))  
					comefromTemp="(来自iPad)";
				else if(comefrom.equals("3"))  
					comefromTemp="(来自Android)";          
				else if(comefrom.equals("4"))  
					comefromTemp="(来自Web手机版)";
			    else
			    	comefromTemp="";       	
				AppItemVo  appItemVo=null;
				if(moodIsActive && discussid != null && !"null".equals(discussid))
				  appItemVo=appDao.getappItemByDiscussId(discussid); 
				String faceimg = "<div class=\"rowWrap moodIcon\" >";
				
				if(appItemVo!=null&&appItemVo.getFaceImg()!=null&&!appItemVo.getFaceImg().equals("")){
					faceimg = faceimg+"<img  src=\""+appItemVo.getFaceImg()+"\" />" ;
				}
				if("<div class=\"rowWrap moodIcon\" style=\"float:right;display:inline;\">".equals(faceimg)){
					faceimg = "";
				}else{
					faceimg += "</div>";
				}
				//地理位置
				List locationList=blogDao.getLocationList(discussid);
				if(locationList!=null&&locationList.size()>0){
					map.put("haslocation",1);
					map.put("location",locationList.get(0));
					map.put("locationData",locationList);
				}else{
					map.put("haslocation",0);
				}
				
				String discussuserid=discessVo.getUserid();            //发表人id
				String isnew=updateList.contains(discussid)?"0":"1";  // 0未读  1 已读
				
				StringBuffer commentstrBuffer = new StringBuffer();
				int repnum1 = 0; 
				int repnum2 = 0;
				List replyList=blogDao.getReplyList(discussuserid, discessVo.getWorkdate(), userid);
				if(replyList.size()>0){
					commentstrBuffer.append("<div class='commentReply'><ul class='reply'>");
					for(int j=0;j<replyList.size();j++){
						BlogReplyVo replyVo=(BlogReplyVo)replyList.get(j);
						String replyid = Util.null2String(replyVo.getId());
						String replyUserid=replyVo.getUserid();
						String replyUsername=resourceComInfo.getLastname(replyUserid);
						String commentType = Util.null2String(replyVo.getCommentType());//私评1
						if("1".equals(commentType)){
							repnum2++;
							commentstrBuffer.append("<li>"+replyUsername+"&nbsp;&nbsp;"+CoworkTransMethod.getFormateDate(replyVo.getCreatedate(),replyVo.getCreatetime())+"(私评)<br>");
						}else{
							repnum1++;
							commentstrBuffer.append("<li>"+replyUsername+"&nbsp;&nbsp;"+CoworkTransMethod.getFormateDate(replyVo.getCreatedate(),replyVo.getCreatetime())+"<br>");
						}
						commentstrBuffer.append("<span class=\"replaycontent\">"+Util.StringReplace(Util.null2String(replyVo.getContent()),"\r\n","")+"</span></li>");
					}
					commentstrBuffer.append("</ul></div>");
				}
				map.put("workdate", workdate);
				map.put("workdateCal", calFormat.format(dateFormat1.parse(workdate)));
				String weekdayCal=week[dateFormat1.parse(workdate).getDay()];
				if(workdate.equals(todaydate)){
					weekdayCal="今天";
				}else if(workdate.equals(yesterday)){
					weekdayCal="昨天";
				}
				map.put("weekdayCal", weekdayCal);
				
				weekday=weekdayCal;
				map.put("weekday", weekday);
				String  isreplenish = discessVo.getIsReplenish();
				if(!("0").equals(isreplenish)){
					isreplenish = "1";
				}
				
				map.put("isreplenish", isreplenish);
				map.put("worddateMD",dateFormat2.format(dateFormat1.parse(workdate)));
				map.put("replycomments", commentstrBuffer.toString());
				map.put("discussuserid", discussuserid);
				
				map.put("username", resourceComInfo.getLastname(discussuserid));
				map.put("userimg", resourceComInfo.getMessagerUrls(discussuserid));
				map.put("createdate",Util.null2String(discessVo.getCreatedate()));
				map.put("createtime", Util.null2String(discessVo.getCreatetime()));
				map.put("moodIcon",faceimg);
				map.put("isnew", isnew);
				String deptname=DepartmentComInfo.getDepartmentname(ResourceComInfo.getDepartmentID(discussuserid));
				map.put("deptname", deptname);//部门名称
				map.put("jbotitle", jobTitlesComInfo.getJobTitlesname(resourceComInfo.getJobTitle(discussuserid)));//岗位名称
				map.put("managerid", resourceComInfo.getManagerID(discussuserid));
				String isshowBj = "";
				String isshowBianJi = "";
				if("".equals(contents)){
					contents = "<div class=\"reportContent\"><div  class=\"nosubmitDiv\">未提交微博</div></div>";
					if(userid.equals(discessVo.getUserid())&&daysFromWorkDate<=blog_makeUpTime){
						isshowBj = "1";
					}
				}else{
					if(userid.equals(discessVo.getUserid())&&daysFromWorkDate<=blog_canEditTime){
						isshowBianJi = "1";
					}
				}
				map.put("isshowBj",isshowBj);
				map.put("isshowBianJi",isshowBianJi);
				map.put("contents",Util.StringReplace(contents.trim(),"\r\n",""));
				
				Date _endDateTmp=dateFormat1.parse(workdate);
				Calendar cal = Calendar.getInstance();
				cal.setTime(_endDateTmp);
				cal.add(Calendar.DATE,-1);
				_endDateTmp = cal.getTime();
				
				map.put("_endDate", dateFormat1.format(_endDateTmp));
				String repstr = "";
				//评分、评论、私评
				/* if(discussid!=null&&!"".equals(discussid)){
					repstr = "<div class=\"replyoperations\"><div class=\"sortInfoRightBar\">"+
						"<span  style='width: 100px' score='2' readOnly='true' discussid='"+discussid+"' target='blog_raty_keep_discussid' class='blog_raty' id='blog_raty_"+discussid+"'></span>"+
						"</div><div>";
				} */
				map.put("replyoperations", repstr);	
				if(repnum1!=0){
					map.put("repnum1","("+repnum1+")");
				}else{
					map.put("repnum1","");
				}
				if(repnum2!=0){
					map.put("repnum2","("+repnum2+")");
				}else{
					map.put("repnum2","");
				}
				datas.add(map);
			}
			if(islog.equals("1")){
				Date d6 = new Date();
				logObj.put("d6",d6.getTime());
				logObj.put("d16",(d1.getTime()-d6.getTime()));
			}
		}
	}catch(Exception e){
		e.printStackTrace();
	}
	detail.put("datas",datas);
	detail.put("totalSize",total+"");
	
	
	detail.put("blogCount",blogCount+"");
	detail.put("myAttentionCount",myAttentionCount+"");
	detail.put("attentionMeCount",attentionMeCount+"");
	
	detail.put("endDate", startDate);
	if(total == 0){
		out.print("{\"totalSize\":0, \"datas\":[]}");
		return;
	}
	JSONObject json = JSONObject.fromObject(detail);
	if(islog.equals("1")){
		json = new JSONObject();
		Date d7 = new Date();
		logObj.put("d7",d7.getTime());
		logObj.put("d17",(d1.getTime()-d7.getTime()));
		json.put("logObj",logObj.toString());
	}
	out.print(json.toString());
	return;
}else if(operation.equals("commentOnMe")){    //评论我的
	ResourceComInfo resourceComInfo=new ResourceComInfo();
	JobTitlesComInfo jobTitlesComInfo=new JobTitlesComInfo();
	enableDate=blogDao.getSysSetting("enableDate");//微博启用时间
	//totalsize
	if(total==0){
		total=blogDao.getCommentTotal(userid);
	}
	BlogServiceImpl bs = new BlogServiceImpl();
	bs.removeCommentRemind(userid);//清除评论数
	
	Map<String, Object> detail = new HashMap<String, Object>();
	List datas = new ArrayList();
	try{
		discussList=blogDao.getCommentDiscussVOList(userid,currentpage,pagesize,total);
		if(discussList.size()>0){
			for(int i=0;i<discussList.size();i++){
				Map map = new HashMap();
				BlogDiscessVo discessVo=(BlogDiscessVo)discussList.get(i);
				if(discessVo==null)
					continue;
				String discussid=discessVo.getId();
				map.put("discussid", Util.null2String(discussid));
				String workdate=discessVo.getWorkdate();
				String showdate=workdate;
				long   todaytime=today.getTime(); 
				long   worktime=dateFormat1.parse(workdate).getTime(); 
				//获取某个工作日到今天已经几天了
				long daysFromWorkDate=(todaytime-worktime)/(24*60*60*1000);
				
				String managerstr=resourceComInfo.getManagersIDs(discessVo.getUserid());
				String createdate="";
				if(discussid!=null)
					createdate=discessVo.getCreatedate();
				else
					createdate=attentionWorkDate;
					
				String comefrom=Util.null2String(discessVo.getComefrom());
				String comefromTemp="";
				if(comefrom.equals("1"))  
					comefromTemp="(来自Iphone)";
				else if(comefrom.equals("2"))  
					comefromTemp="(来自Ipad)";
				else if(comefrom.equals("3"))  
					comefromTemp="(来自Android)";          
				else if(comefrom.equals("4"))  
					comefromTemp="(来自Web手机版)";
			    else
			    	comefromTemp="";       	
				AppItemVo  appItemVo=null;
				if(moodIsActive)
				  appItemVo=appDao.getappItemByDiscussId(discussid); 
				String faceimg = "";
				
				if(appItemVo!=null&&appItemVo.getFaceImg()!=null&&!appItemVo.getFaceImg().equals("")){
					faceimg = "<div class=\"rowWrap\" style=\"float:right;\"><img  width=\"16px\" src=\""+appItemVo.getFaceImg()+"\" /></div>" ;
				}
				//地理位置
				List locationList=blogDao.getLocationList(discussid);
				if(locationList!=null&&locationList.size()>0){
					map.put("haslocation",1);
					map.put("location",locationList.get(0));
					map.put("locationData",locationList);
				}else{
					map.put("haslocation",0);
				}
				
				String discussuserid=discessVo.getUserid();            //发表人id
				String isnew=updateList.contains(discussid)?"0":"1";  // 0未读  1 已读
				
				StringBuffer commentstrBuffer = new StringBuffer();
				int repnum1 = 0;
				int repnum2 = 0;
				List replyList=blogDao.getReplyList(discussuserid, discessVo.getWorkdate(), userid);
				//BlogReplyVo replyArray[]=new BlogReplyVo[replyList.size()];
				if(replyList.size()>0){
					commentstrBuffer.append("<div class='commentReply'><ul class='reply'>") ;
					for(int j=0;j<replyList.size();j++){
						BlogReplyVo replyVo=(BlogReplyVo)replyList.get(j);
						String replyid = Util.null2String(replyVo.getId());
						String replyUserid=replyVo.getUserid();
						String replyUsername=resourceComInfo.getLastname(replyUserid);
						String commentType = Util.null2String(replyVo.getCommentType());//私评1
						if("1".equals(commentType)){
							repnum2++;	
							commentstrBuffer.append("<li>"+replyUsername+"&nbsp;&nbsp;"+CoworkTransMethod.getFormateDate(replyVo.getCreatedate(),replyVo.getCreatetime())+"(私评)<br>");
						}else{
							repnum1++;
							commentstrBuffer.append("<li>"+replyUsername+"&nbsp;&nbsp;"+CoworkTransMethod.getFormateDate(replyVo.getCreatedate(),replyVo.getCreatetime())+"<br>");
						}
						commentstrBuffer.append("<span class=\"replaycontent\">"+Util.StringReplace(Util.null2String(replyVo.getContent()),"\r\n","")+"</span></li>");
					}
					commentstrBuffer.append("</ul></div>");
				}
				workdate = discessVo.getWorkdate();
				map.put("workdate", workdate);
				map.put("workdateCal", calFormat.format(dateFormat1.parse(workdate)));
				String weekdayCal=week[dateFormat1.parse(workdate).getDay()];
				if(workdate.equals(todaydate)){
					weekdayCal="今天";
				}else if(workdate.equals(yesterday)){
					weekdayCal="昨天";
				}
				map.put("weekdayCal", weekdayCal);
				
				String weekday=weekdayCal;
				map.put("weekday", weekday);
				map.put("worddateMD",dateFormat2.format(dateFormat1.parse(workdate)));
				
				map.put("replycomments", commentstrBuffer.toString());
				map.put("discussuserid", discussuserid);
				map.put("username", resourceComInfo.getLastname(discussuserid));
				map.put("userimg", resourceComInfo.getMessagerUrls(discussuserid));
				map.put("createdate",Util.null2String(discessVo.getCreatedate()));
				map.put("createtime", Util.null2String(discessVo.getCreatetime()));
				map.put("moodIcon",faceimg);
				map.put("isnew", isnew);
				String deptname=DepartmentComInfo.getDepartmentname(ResourceComInfo.getDepartmentID(discussuserid));
				map.put("deptname", deptname);//部门名称
				map.put("jbotitle", jobTitlesComInfo.getJobTitlesname(resourceComInfo.getJobTitle(discussuserid)));//岗位名称
				map.put("managerid", resourceComInfo.getManagerID(discussuserid));
				String contents = Util.null2String(discessVo.getContent());//微博内容
				if("".equals(contents)){
					contents = "<div class=\"reportContent\"><div  class=\"nosubmitDiv\">未提交微博</div></div>";
				}
				map.put("contents",Util.StringReplace(contents.trim(),"\r\n",""));
				if(repnum1!=0){
					map.put("repnum1","("+repnum1+")");
				}else{
					map.put("repnum1","");
				}
				if(repnum2!=0){
					map.put("repnum2","("+repnum2+")");
				}else{
					map.put("repnum2","");
				}
				datas.add(map);
			}
		}
	}catch(Exception e){
		e.printStackTrace();
	}
	
	detail.put("datas",datas);
	detail.put("totalSize",total+"");
	if(total == 0){
		out.print("{\"totalSize\":0, \"datas\":[]}");
		return;
	}
	JSONObject json = JSONObject.fromObject(detail);
	out.print(json.toString());
}else if(operation.equals("markRead")){
	String discussuserid=Util.null2String(fu.getParameter("discussuserid"));
	String discussid=Util.null2String(fu.getParameter("discussid")); 
	BlogServiceImpl bs = new BlogServiceImpl();
	bs.writeBlogReadFlag(userid, discussuserid, discussid);
	result.put("flag", 1);
	JSONObject json = JSONObject.fromObject(result);
	out.print(json.toString());	
}else if(operation.equals("myAttention")){    //我的关注
	Calendar calendar = Calendar.getInstance();
	int currentMonth = calendar.get(Calendar.MONTH) + 1;
	int currentYear = calendar.get(Calendar.YEAR);
	BlogReportManager reportManager=new BlogReportManager();
	reportManager.setUser(user);
	
	 String from=Util.null2String(fu.getParameter("from"));
	 userid=Util.null2String(fu.getParameter("userid"));
		
	 String currentUserid=""+user.getUID();
	 String bid=Util.null2String(fu.getParameter("blogid"));
	 if(!"".equals(bid)){
		 currentUserid = bid;
	 }
	 
	String blogCount=""+blogDao.getMyBlogCount(currentUserid);               //微博总数
	String myAttentionCount=""+blogDao.getMyAttentionCount(currentUserid,"all");   //我关注的人总数
	String attentionMeCount=""+blogDao.getAttentionMe(currentUserid).size();        //关注我的人总数
		
	 JobTitlesComInfo jobTitlesComInfo=new JobTitlesComInfo();

	 String allowRequest=blogDao.getSysSetting("allowRequest");    //系统申请设置情况
	 
	 BlogShareManager shareManager=new BlogShareManager();
	 String managerstr="','+t.managerstr+','";
	 RecordSet recordSet=new RecordSet();
	 if(recordSet.getDBType().equals("oracle"))
		managerstr="','||t.managerstr||','"; 
	 
	 Map<String, Object> detail = new HashMap<String, Object>();
	 String keyworkd = Util.null2String(fu.getParameter("keyword"));
	 List blogList = new ArrayList();
	 
	 if("".equals(keyworkd)){
		
		blogList=blogDao.getBlogMapList(currentUserid,"attention",null);
	 }else{
		 
		 Map conditionAttn = new HashMap();
		 conditionAttn.put("keyworkd",keyworkd);
		 blogList=blogDao.getBlogMapList(currentUserid,"searchList",conditionAttn);
	 }
	    
	 List datas = new ArrayList();
	 if(blogList.size()>0){
		 for(int i=0;i<blogList.size();i++){
		 	Map map=(Map)blogList.get(i);	
		    String attentionid=(String)map.get("attentionid");
		    String isnew=(String)map.get("isnew");
		    String isshare=(String)map.get("isshare");//主动共享
		    String isSpecified=(String)map.get("isSpecified"); //指定共享
		    String isattention=(String)map.get("isattention");
		    String islower=(String)map.get("islower");
		    String iscancel=(String)map.get("iscancel");
		    String status="0";                  //不在共享和关注范围内
		    if(isshare.equals("1") || isSpecified.equals("1"))                 //在共享范围内
		  	  status="1";
		    if(status.equals("1")&&isattention.equals("1")) //在关注范围内
		  	  status="2";
		    if(status.equals("2")&&islower.equals("1")&&iscancel.equals("1"))
		  	  status="1";
		    if(status.equals("0")){
		  	  int isReceive=1;
		  	  RecordSet recordSet2=new RecordSet();
		  	  String sqlStr="select isReceive from blog_setting where userid="+attentionid;
		  	  recordSet2.execute(sqlStr);
		  	  if(recordSet2.next())
		  		 isReceive=recordSet2.getInt("isReceive");
		  	  if(isReceive==0)
		  		 status="-1";             //不允许申请
		  	  if(allowRequest.equals("0"))
		  		  status="-1";             //系统设置为不允许申请
		    }
	        String username=ResourceComInfo.getLastname(attentionid);
	        if(!keyworkd.equals("")){
	        	if(username.indexOf(keyworkd)==-1){
	        		continue;
	        	}
	        }
	        Map resultMap = reportManager.getBlogReportByUser(attentionid,currentYear, currentMonth);
			double workIndex = ((Double) resultMap.get("workIndex")).doubleValue(); //工作指数
			double workIndex2 = Math.floor(((Double) resultMap.get("workIndex")).doubleValue()*2); //工作指数
			int z = (int)workIndex2;
			
	        String userimg=ResourceComInfo.getMessagerUrls(attentionid);
	        String deptName=DepartmentComInfo.getDepartmentname(ResourceComInfo.getDepartmentID(attentionid));
			map.put("id",attentionid);
			map.put("messagerurl",ResourceComInfo.getMessagerUrls(attentionid));
			map.put("username",username);
			map.put("userimg",userimg);
			map.put("deptname",deptName);
			map.put("status",status);
			map.put("workIndex",workIndex);
			map.put("workIndexClass",z);
			map.put("jbotitle", jobTitlesComInfo.getJobTitlesname(ResourceComInfo.getJobTitle(attentionid)));//岗位名称
			datas.add(map);
		 }
	}
	total = datas.size();
	detail.put("datas",datas);
	detail.put("totalSize",total+"");
	detail.put("blogCount",blogCount);
	detail.put("myAttentionCount",myAttentionCount);
	detail.put("attentionMeCount",attentionMeCount);
	JSONObject json = JSONObject.fromObject(detail);
	out.print(json.toString());
			 
}else if(operation.equals("attentionMe")){    //关注我的
	Calendar calendar = Calendar.getInstance();
	int currentMonth = calendar.get(Calendar.MONTH) + 1;
	int currentYear = calendar.get(Calendar.YEAR);
	BlogReportManager reportManager=new BlogReportManager();
	reportManager.setUser(user);
	
	String from=Util.null2String(fu.getParameter("from"));
	userid=""+user.getUID();
	String attentionedid=Util.null2String(fu.getParameter("userid"));
	String bid=Util.null2String(fu.getParameter("blogid"));
	if(!"".equals(bid)){
		attentionedid = bid;
	}
	
	String blogCount=""+blogDao.getMyBlogCount(attentionedid);               //微博总数
	String myAttentionCount=""+blogDao.getMyAttentionCount(attentionedid,"all");   //我关注的人总数
	String attentionMeCount=""+blogDao.getAttentionMe(attentionedid).size();        //关注我的人总数
	
	String keyworkd = Util.null2String(fu.getParameter("keyword"));
	List blogList=blogDao.getAttentionMe(attentionedid);

	JobTitlesComInfo jobTitlesComInfo=new JobTitlesComInfo();
	BlogShareManager shareManager=new BlogShareManager();
	 
	 Map<String, Object> detail = new HashMap<String, Object>();
	 List datas = new ArrayList();
	 if(blogList.size()>0){
		 for(int i=0;i<blogList.size();i++){
			Map map=new HashMap();	
			String attentionid=(String)blogList.get(i);
			int status=shareManager.viewRight(attentionid,userid);
			String islower="0";
			if(status==2||status==4) {
				islower="1";
			}
			String username=ResourceComInfo.getLastname(attentionid);
			if(!keyworkd.equals("")){
	        	if(username.indexOf(keyworkd)==-1){
	        		continue;
	        	}
	        }
			String userimg=ResourceComInfo.getMessagerUrls(attentionid);
			String deptName=DepartmentComInfo.getDepartmentname(ResourceComInfo.getDepartmentID(attentionid));
			
			Map resultMap = reportManager.getBlogReportByUser(attentionid,currentYear, currentMonth);
			double workIndex = ((Double) resultMap.get("workIndex")).doubleValue(); //工作指数
			double workIndex2 = Math.floor(((Double) resultMap.get("workIndex")).doubleValue()*2); //工作指数
			int z = (int)workIndex2;
			
			map.put("id",attentionid);
			map.put("islower",islower);
			map.put("status",status);
			map.put("userimg",ResourceComInfo.getMessagerUrls(attentionid));
			map.put("username",username);
			map.put("deptname",deptName);
			map.put("workIndex",workIndex);
			map.put("workIndexClass",z);
			map.put("jbotitle", jobTitlesComInfo.getJobTitlesname(ResourceComInfo.getJobTitle(attentionid)));//岗位名称
			datas.add(map);
		 }
	}
	total = datas.size();
	detail.put("datas",datas);
	detail.put("totalSize",total+"");
	detail.put("blogCount",blogCount);
	detail.put("myAttentionCount",myAttentionCount);
	detail.put("attentionMeCount",attentionMeCount);
	JSONObject json = JSONObject.fromObject(detail);
	out.print(json.toString());
			 
}else if(operation.equals("changeAttention")){//关注处理
	String type=Util.null2String(fu.getParameter("type"));
	String attentionid=Util.null2String(fu.getParameter("attentionid"));
	String islower=Util.null2String(fu.getParameter("islower"));
	String status=Util.null2String(fu.getParameter("status"));
	if(status.equals("add")){                 //添加关注
	    blogManager.addAttention(userid,attentionid,islower);
	    blogDao.addRemind(attentionid,userid,"5","","0");  //关注我的+1提醒
	}else if(status.equals("cancel")){       //取消关注
		blogManager.cancelAttention(userid,attentionid,islower);
	}else if(status.equals("request")){     //申请关注
		blogManager.requestAttention(userid,attentionid,islower);
	}
	JSONObject json = new JSONObject();
	json.put("s",1);
	out.print(json.toString());
}else if(operation.equals("myReport")){    //我的报表
	Calendar calendar=Calendar.getInstance();
	int currentMonth=calendar.get(Calendar.MONTH)+1;
	int currentYear=calendar.get(Calendar.YEAR);
	
	
	int year=Util.getIntValue(fu.getParameter("year"),currentYear);
	int month=Util.getIntValue(fu.getParameter("month"),currentMonth);
	int currentDay=calendar.get(Calendar.DAY_OF_MONTH);
	if(currentMonth==month && currentDay==1){
		out.print("{\"totalWorkday\":0,\"moodReportList\":[],\"totaldateList\":[], \"reportList\":[]}");
		return;
	}
	
	String monthStr=month<10?("0"+month):(""+month);
	
	BlogReportManager reportManager=new BlogReportManager();
	reportManager.setUser(user);
	Map blogResultMap=reportManager.getBlogReportByUser(userid,year,month); 
	Map moodResultMap=reportManager.getMoodReportByUser(userid,year,month); 
	
	List reportList=(List)blogResultMap.get("reportList");
	List moodReportList=(List)moodResultMap.get("reportList");
	
	List totaldateList=(List)blogResultMap.get("totaldateList");          //当月总的天数
	int totalWorkday=((Integer)blogResultMap.get("totalWorkday")).intValue();    //当月工作日总数
	int totalUnsubmit=((Integer)blogResultMap.get("totalUnsubmit")).intValue();  //微博未提交总数
	double workIndex=((Double)blogResultMap.get("workIndex")).doubleValue();        //工作指数
	double moodIndex=((Double)moodResultMap.get("moodIndex")).doubleValue();    //心情指数
	
	String isSignInOrSignOut=Util.null2String(blogDao.getIsSignInOrSignOut());
	if(appDao.getAppVoByType("mood").isActive()) {
		
	}
	Map<String, Object> detail = new HashMap<String, Object>();
	
	List scheduleReportList =new ArrayList();
	if(isSignInOrSignOut.equals("1")){
		Map schedulrResultMap=reportManager.getScheduleReportByUser(userid,year,month); 
		scheduleReportList=(List)schedulrResultMap.get("reportList"); 
	}
	
	List dayList = new ArrayList();
	for(int i=0;i<totaldateList.size();i++){ 
		if(i<scheduleReportList.size()){
	    	   Map map=(Map)scheduleReportList.get(i);
	    	   boolean isWorkday=((Boolean)map.get("isWorkday")).booleanValue();
	    	   if(isWorkday){
	    		   dayList.add(totaldateList.get(i));
	    	   }
    	}else{
    		dayList.add(totaldateList.get(i));
    	}
	}
	totaldateList = dayList;
	
	total = totaldateList.size();
	detail.put("totalWorkday",totalWorkday);//工作日总数
	detail.put("ismood",appDao.getAppVoByType("mood").isActive());//是否启用心情
	detail.put("moodReportList",moodReportList);
	detail.put("isSignInOrSignOut",isSignInOrSignOut);//是否启用签到签退
	detail.put("scheduleReportList",scheduleReportList);
	detail.put("totaldateList",totaldateList);//工作日列表
	detail.put("reportList",reportList);//微博报表
	JSONObject json = JSONObject.fromObject(detail);
	out.print(json.toString());
			 
}else if(operation.equals("myAttentionReport")){    //关注报表
	  Calendar calendar=Calendar.getInstance();
	  int currentMonth=calendar.get(Calendar.MONTH)+1;
	  int currentYear=calendar.get(Calendar.YEAR);
	  int year=Util.getIntValue(fu.getParameter("year"),currentYear);
	  int month=Util.getIntValue(fu.getParameter("month"),currentMonth);
	  
	  int currentDay=calendar.get(Calendar.DAY_OF_MONTH);
	  if(currentMonth==month && currentDay==1){
		  out.print("{\"totalSize\":0, \"resultList\":[]}");
		  return;
	  }
	  
	  String monthStr=month<10?("0"+month):(""+month);
	  BlogReportManager reportManager=new BlogReportManager();
	  reportManager.setUser(user);
	  Map resultMap=new HashMap();
	  int allUnsubmit=0;
	  int allWorkday=0;
	  double allWorkIndex=0;
	  resultMap=reportManager.getBlogAttentionReport(userid,year,month);
	  if(resultMap.size()==0){
		out.print("{\"totalSize\":0, \"resultList\":[]}");
		return;
	  }
	  allUnsubmit=((Integer)resultMap.get("allUnsubmit")).intValue();      //被关注人未提交总数
	  allWorkday=((Integer)resultMap.get("allWorkday")).intValue();      //被关注人未提交总数
	  allWorkIndex=((Double)resultMap.get("allWorkIndex")).doubleValue();      //被关注人未提交总数
	  List resultList=(List)resultMap.get("resultList");          //统计结果
	  List totaldateList=(List)resultMap.get("totaldateList");          //当月总的天数
	  int totalWorkday=((Integer)resultMap.get("totalWorkday")).intValue();    //当月工作日总数
	  List isWorkdayList=(List)resultMap.get("isWorkdayList");    //有效日期统计list
	  List resultCountList=(List)resultMap.get("resultCountList"); //有效日期统计list
	  Map<String, Object> detail = new HashMap<String, Object>();
	
	
	for(int i=0;i<resultList.size();i++){
		Map reportMap=(Map)resultList.get(i);
		String attentionid=(String)reportMap.get("attentionid");
		List reportList=(List)reportMap.get("reportList");
		int totalUnsubmit=((Integer)reportMap.get("totalUnsubmit")).intValue();
		double workIndex=((Double)reportMap.get("workIndex")).doubleValue();
		String lastname  = ResourceComInfo.getLastname(attentionid);
		List list = new ArrayList();
		for(int j=0;j<totaldateList.size();j++){
		     if(j<isWorkdayList.size()){	 
		       boolean isWorkday=((Boolean)isWorkdayList.get(j)).booleanValue();
		       boolean isSubmited=((Boolean)reportList.get(j)).booleanValue();
		       if(isWorkday){
		    	   list.add(isSubmited);
		       }
		     }
		}
		reportMap.put("name",lastname);
		reportMap.put("userimg", ResourceComInfo.getMessagerUrls(attentionid));
		reportMap.put("submitList",list);
		resultList.set(i,reportMap);
	}
	List dayList = new ArrayList();
	for(int i=0;i<totaldateList.size();i++){ 
		if(i<isWorkdayList.size()){	 
	       boolean isWorkday=((Boolean)isWorkdayList.get(i)).booleanValue();
    	   if(isWorkday){
    		   dayList.add(totaldateList.get(i));
    	   }
    	}else{
    		dayList.add(totaldateList.get(i));
    	}
	}
	
	totaldateList = dayList;
	total = totaldateList.size();
	detail.put("totaldateList",totaldateList);//工作日列表
	detail.put("resultList",resultList);//工作日列表
	JSONObject json = JSONObject.fromObject(detail);
	out.print(json.toString());
}else if(operation.equals("saveBlog")){
	//ConnStatement cs = new ConnStatement();
	RecordSet rs = new RecordSet();
	String curTime=new SimpleDateFormat("HH:mm:ss").format(today);//当前时间
	//boolean isoracle = (cs.getDBType()).equals("oracle");
	content=URLDecoder.decode(Util.null2String(fu.getParameter("content")), "UTF-8");//日志内容
	
	String forDate=Util.null2String(fu.getParameter("forDate"));
	if(forDate==null||forDate.equals("")){
		forDate = curDate;
	}
	String appType=Util.null2String(fu.getParameter("type"));
	String appItemId=Util.null2String(fu.getParameter("appItemId"),"1");
	int discussid=Util.getIntValue(Util.null2String(fu.getParameter("discussid")),0);
	String score="0";
	String comefrom="0";
	boolean isEdit=discussid!=0?true:false;  //是否是编辑
	
	String lastUpdateTime=""+today.getTime();
	String sql="";
	boolean isAppend=false;
	ConnStatement cs = null;
	try{
		cs = new ConnStatement();
		boolean isoracle = (cs.getDBType()).equals("oracle");
		appItemId=appItemId.equals("2")?appItemId:"1"; //处理心情丢失情况
	if(!isEdit){ //如果微博记录id=0 则表示为创建
		BlogDiscessVo discessVo=blogDao.getDiscussVoByDate(userid,forDate);
		if(discessVo!=null){ //判断是否为新增微薄，discessVo为null为新增，否则当天的内容追加当天内容下：冯广硕
		 if(discessVo.getUserid().equals(userid)){ //防止通过ajax更新他人微博
			isAppend=true;
			content = "<br>"+content;
			content=discessVo.getContent()+content;
			if(isoracle){//oracle数据库的clob字段需要用流的方式加到数据库
				
			
			sql="update blog_discuss set lastUpdatetime=?,content=empty_clob() where id=?";
			cs.setStatementSql(sql);
			cs.setString(1,lastUpdateTime);
			//cs.setString(2,"empty_clob()");
			cs.setString(2,discessVo.getId());
			cs.executeUpdate();
			sql="select content from blog_discuss where id=? for update ";
			cs.setStatementSql(sql, false);
			cs.setString(1,discessVo.getId());
            cs.executeQuery();
            cs.next();
            CLOB theclob = cs.getClob(1);

            String contenttemp = content; // (new
            // String(this.doccontent.getBytes("ISO8859_1"),
            // "GBK")) ;
            char[] contentchar = contenttemp.toCharArray();
            Writer contentwrite = theclob.getCharacterOutputStream();
            contentwrite.write(contentchar);
            contentwrite.flush();
            contentwrite.close();
            
			}else{
			sql="update blog_discuss set lastUpdatetime=?,content=? where id=?";
			cs.setStatementSql(sql);
			cs.setString(1,lastUpdateTime);
			cs.setString(2,content);
			cs.setString(3,discessVo.getId());
			}			
		   }	
		}else{//新增微薄
		 if (isoracle) {
		 sql="insert into blog_discuss (userid, createdate, createtime,content,lastUpdatetime,isReplenish,workdate,score,comefrom)"+
				"values (?, ?,?,empty_clob(),?,?,?,?,?)";
			cs.setStatementSql(sql);
			cs.setString(1,""+userid);
			cs.setString(2,""+curDate);
			cs.setString(3,""+curTime);
			//cs.setString(4,"empty_clob()");
			cs.setString(4,""+lastUpdateTime);
			cs.setString(5,""+(forDate.equals(curDate)?"0":"1"));
			cs.setString(6,""+forDate);
			cs.setString(7,"0");
			cs.setString(8,"0");
		    cs.executeUpdate();
		   
		    sql="select content from  blog_discuss where id = (select id from blog_discuss where userid="+userid+" and createdate='"+curDate+"' and createtime='"+curTime+"') for update ";
			cs.setStatementSql(sql, false);
            cs.executeQuery();
            cs.next();
            CLOB theclob = cs.getClob(1);

            String contenttemp = content; // (new
            // String(this.doccontent.getBytes("ISO8859_1"),
            // "GBK")) ;
            char[] contentchar = contenttemp.toCharArray();
            Writer contentwrite = theclob.getCharacterOutputStream();
            contentwrite.write(contentchar);
            contentwrite.flush();
            contentwrite.close();
            
		 
		 }else{
			sql="insert into blog_discuss (userid, createdate, createtime,content,lastUpdatetime,isReplenish,workdate,score,comefrom)"+
				"values (?, ?,?,?,?,?,?,?,?)";	
			cs.setStatementSql(sql);
			cs.setString(1,""+userid);
			cs.setString(2,""+curDate);
			cs.setString(3,""+curTime);
			cs.setString(4,""+content);
			cs.setString(5,""+lastUpdateTime);
			cs.setString(6,""+(forDate.equals(curDate)?"0":"1"));
			cs.setString(7,""+forDate);
			cs.setString(8,"0");
			cs.setString(9,"0");
			}
			
		}
	
	}else{            //更新
	if(isoracle){
		
	    sql="update blog_discuss set lastUpdatetime=?,content=empty_clob() where id=? and userid="+userid;
		cs.setStatementSql(sql);
		cs.setString(1,""+lastUpdateTime);
		//cs.setString(2,"empty_clob()");
		cs.setString(2,""+discussid);
		 if(cs.executeUpdate()>0){ //判断是否为修改自身微博 
		  sql="select content from  blog_discuss where id =? for update " ;
		   cs.setStatementSql(sql, false);
			cs.setString(1,""+discussid);
            cs.executeQuery();
            cs.next();
            CLOB theclob = cs.getClob(1);

            String contenttemp = content; // (new
            // String(this.doccontent.getBytes("ISO8859_1"),
            // "GBK")) ;
            char[] contentchar = contenttemp.toCharArray();
            Writer contentwrite = theclob.getCharacterOutputStream();
            contentwrite.write(contentchar);
            contentwrite.flush();
            contentwrite.close();
		 }  
	}else{
	    sql="update blog_discuss set lastUpdatetime=?,content=? where id=? and userid="+userid;
		cs.setStatementSql(sql);
		cs.setString(1,""+lastUpdateTime);
		cs.setString(2,""+content);
		cs.setString(3,""+discussid);
	}
	}
	
	HashMap backData=new HashMap();
	if(cs.executeUpdate()>0){
		cs.close(); //关闭数据库连接
		
		//如果是编辑，则取创建时的时间
		if(isEdit){
			BlogDiscessVo discessVo=blogDao.getDiscussVo(""+discussid);	
			curDate=discessVo.getCreatedate();
			curTime=discessVo.getCreatetime();
			score=discessVo.getScore();
			comefrom=discessVo.getComefrom();
		}
		if(curDate.equals(forDate)){//当天提交微博
			sql="select max(id) as maxid  from blog_discuss where userid="+userid+" and workdate='"+curDate+"'";
			rs.executeSql(sql);
			if(rs.next()){
				discussid=rs.getInt("maxid");
				String lng=Util.null2String(fu.getParameter("lng"));
				String lat=Util.null2String(fu.getParameter("lat"));
				String addr=Util.null2String(fu.getParameter("addr"));
				 if(!addr.equals("")){ //包含地理位置并且非补交 
					  String locationName=addr;
					  String location=lat+","+lng;
					  sql="select id from blog_location where discussid="+discussid+" and (location='"+location+"' or locationName='"+locationName+"')";
					  rs.executeSql(sql);
					  if(!rs.next()){
						  sql="insert into blog_location(discussid,location,locationName,createtime) values("+discussid+",'"+location+"','"+locationName+"','"+curTime+"')";
					      rs.executeSql(sql);
					  }
				  }
			}
		}
		
		backData.put("id",""+discussid);
		backData.put("curDate",curDate);
		backData.put("curTime",curTime);
		backData.put("forDate",forDate);
		
		String createdatetime=dateFormat3.format(dateFormat.parse(curDate+" "+curTime));
		backData.put("createdatetime",createdatetime);
		backData.put("score",score);
		backData.put("isManagerScore",isManagerScore);
		
		backData.put("comefrom",comefrom);
		
		backData.put("userName",user.getLastname());
		backData.put("userid",""+user.getUID());
		
		String type=(!forDate.equals(curDate))?"1":"0"; //是否为补交  1补交 0正常提交
		backData.put("type",type);
		
		result.put("status","1");  //保存是否成功
		
		if(appDao.getAppVoByType("mood").isActive()){
			if(!isEdit&&!isAppend){
				sql="INSERT INTO blog_appDatas(userid,workDate,createDate,createTime,discussid,appitemId)"+
					 "VALUES('"+user.getUID()+"','"+forDate+"','"+curDate+"','"+curTime+"','"+discussid+"','"+appItemId+"')";
			}else{
				sql="update blog_appDatas set  appitemId='"+appItemId+"' where discussid='"+discussid+"'";
			}
			rs.executeSql(sql);
			sql="SELECT * FROM blog_appDatas LEFT JOIN blog_AppItem ON blog_appDatas.appItemId=blog_AppItem.id WHERE discussid='"+discussid+"'";
			rs.executeSql(sql);
			if(rs.next()){
				backData.put("appItemId",appItemId);
				backData.put("faceImg",rs.getString("face"));
				backData.put("itemName",SystemEnv.getHtmlLabelName(Util.getIntValue(rs.getString("itemName")),user.getLanguage()));
			}
		}
		//提交新的微博时给予提醒
		if(!isEdit&&!isAppend){
			//删除阅读记录
			sql="DELETE FROM blog_read WHERE blogid='"+user.getUID()+"'";
			rs.executeSql(sql);
			
			//给关注我的人发送微博提交提醒
			List attentionMeList=blogDao.getAttentionMe(userid);
			for(int i=0;i<attentionMeList.size();i++){
				blogDao.addRemind((String)attentionMeList.get(i),userid,"6",""+discussid,"0");
			}
		}
		
		result.put("backdata",backData);
		JSONObject json=JSONObject.fromObject(result);
		out.println(json);
	}else{
		result.put("status","0");
		JSONObject json=JSONObject.fromObject(result);
		out.println(json);
	}
	}catch(Exception e){
		e.printStackTrace();
	}
	finally{
		if(cs != null)
		cs.close();
	}
}else if(operation.equals("pl")){//评论微博
	//ConnStatement cs = new ConnStatement();
	RecordSet rs = new RecordSet();
	String curTime=new SimpleDateFormat("HH:mm:ss").format(today);//当前时间
	
	content=URLDecoder.decode(Util.null2String(fu.getParameter("content")), "UTF-8");//日志内容
	String discussid=Util.null2String(fu.getParameter("discussid"));//被评论的日志id
	String replyid=Util.null2String(fu.getParameter("replyid"));//被评论的评论的id
	String tempreplyid=Util.null2String(fu.getParameter("replyid")); //被评论的评论的id
	
	String relatedid=Util.null2String(fu.getParameter("relatedid")); //评论中相关人id
	
	String commentType=Util.null2String(fu.getParameter("commentType"));//被评论的日志id
	String workdate=Util.null2String(fu.getParameter("workdate"));//被评论的评论的id
	String bediscussantid=Util.null2String(fu.getParameter("bediscussantid"));//被评论的评论的id

	String action=Util.null2String(fu.getParameter("action")).trim();
	
	HashMap backData=new HashMap();
	ArrayList array=new ArrayList();
	String remindSql="";
	ConnStatement cs = null;
	try{
		cs = new ConnStatement();
		String sql="insert into blog_reply (userid, discussid, createdate, createtime, content,comefrom,workdate,bediscussantid,commentType,relatedid)"+
			"VALUES (?, ?,?,?,?,?,?,?,?,?)";
		cs.setStatementSql(sql);
		cs.setString(1,""+userid);
		cs.setString(2,""+discussid);
		cs.setString(3,""+curDate);
		cs.setString(4,""+curTime);
		cs.setString(5,""+content);
		cs.setString(6,"0");
		cs.setString(7,""+workdate);
		cs.setString(8,""+bediscussantid);
		cs.setString(9,""+commentType);
		cs.setString(10,""+relatedid);
		if(cs.executeUpdate()>0){ 
			//cs.close();
			sql="select max(id) maxid from blog_reply where userid="+userid;
			rs.execute(sql);
			rs.next();
			replyid=rs.getString("maxid");
			result.put("status","1");
			backData.put("id",replyid);
			backData.put("discussid",discussid);
			backData.put("createDate",curDate);
			backData.put("createTime",curTime);
			backData.put("createTime",curTime);
			
			String createdatetime=dateFormat3.format(dateFormat.parse(curDate+" "+curTime));
			backData.put("createdatetime",createdatetime);
			
			backData.put("userid",new Integer(user.getUID()));
			backData.put("username",user.getLastname());
			
			backData.put("commentType",commentType);
			
			result.put("backdata",backData);
			JSONObject json=JSONObject.fromObject(result);
			out.println(json);
		}else{
			result.put("status","0");
			result.put("backdata",SystemEnv.getHtmlLabelName(83155,user.getLanguage()));
			JSONObject json=JSONObject.fromObject(result);
			out.println(json);
		}
		}catch(Exception e){}
		finally{
			if(cs != null)
				cs.close();
		}
		BlogDao blogdao=new BlogDao();
		if(!"0".equals(tempreplyid)){
			if(!bediscussantid.equals(userid))
				blogdao.addRemind(bediscussantid,userid,"9",discussid+"|0|"+replyid,"0");
			
			if(!relatedid.equals(userid)&&!bediscussantid.equals(relatedid))
			    blogdao.addRemind(relatedid,userid,"9",discussid+"|"+tempreplyid+"|"+replyid,"0");
		}else{ 
			
			if(!bediscussantid.equals(userid))
				   blogdao.addRemind(bediscussantid,userid,"9",discussid+"|0|"+replyid,"0");
		}
		// 更新访问记录时间
        blogdao.addVisitRecord(userid, bediscussantid);
		
}else if(operation.equals("getBlogCount")){    //获取微博数字
	Map count=blogDao.getReindCount(user); 
	JSONObject json = JSONObject.fromObject(count);
	out.print(json.toString());
	return;
}else if(operation.equals("getAttnStatus")){    //获取关注关系
	BlogShareManager shareManager=new BlogShareManager();
	String blogId=Util.null2String(fu.getParameter("blogId")); 
	int status=shareManager.viewRight(blogId,userid); //日志查看权限
	out.print(status);
}else if(operation.equals("addAttention")){    //添加关注
	String blogId=Util.null2String(fu.getParameter("blogId"));
	String islower=Util.null2String(fu.getParameter("islower"));
	blogManager.addAttention(userid,blogId,islower);
    blogDao.addRemind(blogId,userid,"5","","0");  //关注我的+1提醒
    
}else if(operation.equals("cancelAttention")){    //取消关注
	String blogId=Util.null2String(fu.getParameter("blogId"));
	String islower=Util.null2String(fu.getParameter("islower"));
	blogManager.cancelAttention(userid,blogId,islower);
	
}else if(operation.equals("applyAttention")){    //申请关注
	String blogId=Util.null2String(fu.getParameter("blogId"));
	String islower=Util.null2String(fu.getParameter("islower"));
	blogManager.requestAttention(userid,blogId,islower);
}else if(operation.equals("getAttnRemindNum")){
	RecordSet rs = new RecordSet();
    String sql="select * from blog_remind where remindid="+userid+" and remindType=1 and (status=0 or status=1) order by createdate desc,createtime desc";
    rs.execute(sql);
    int i=0;
    while(rs.next()){
    	i++;
    }
	out.print(i);
	return;
}else if(operation.equals("getAttnRemindMsg")){
	List remindList = new ArrayList();
	RecordSet rs = new RecordSet();
    String sql="select * from blog_remind where remindid="+userid+" and remindType=1 and (status=0 or status=1) order by createdate desc,createtime desc";
    rs.execute(sql);
    while(rs.next()){
    	 Map map = new HashMap();
         map.put("id", rs.getString("id"));
         map.put("remindid", rs.getString("remindid"));
         map.put("relatedid", rs.getString("relatedid"));
         map.put("username", ResourceComInfo.getLastname(rs.getString("relatedid")));
         map.put("remindType", rs.getString("remindType"));
         map.put("createdate", rs.getString("createdate"));
         map.put("createtime", rs.getString("createtime"));
         map.put("remindValue", rs.getString("remindValue"));
         map.put("status", rs.getString("status"));

         remindList.add(map);
    }
    JSONArray json = JSONArray.fromObject(remindList);
	out.print(json.toString());
	return;
}else if(operation.equals("dealrequest")){
	String requestid=Util.null2String(fu.getParameter("requestid"));
	String relatedid=Util.null2String(fu.getParameter("relatedid"));
	String status=Util.null2String(fu.getParameter("status"));
	blogManager.dealRequest(userid,relatedid,requestid,status);
	if(status.equals("1")){        //同意
	   blogDao.addRemind(relatedid,userid,"2","","0");  //申请成功提醒
	}else if(status.equals("-1"))  //拒绝
	   blogDao.addRemind(relatedid,userid,"3","","0");	//申请失败提醒
}
%>
